<template>
	<view class="my-team full box relative bg-primary flex-col">
		<view class="tab-wrap">
			<u-tabs active-color="#3361F0" :bar-height="6" :bold="false" :list="tabList" :is-scroll="false"
				v-model="currentTab" @change="handleTabChange" :bar-style="{bottom:'-4px'}" />
		</view>
		<view class="w-wrap">
			<view class="w-inner">
				<mescroll-uni @init="mescrollInit" :fixed="false" @down="downCallback" @up="upCallback">
					<view class="record-list">
						<view class="record-item" v-for="(item,index) in list" :key="index"
							@click="handleToDetail(item)">
							<image :src="item.avatar" class="item-avatar" mode="aspectFill"></image>
							<view class="item-info">
								<text class="item-text">{{ item.nickname }}<text
										v-if="item.real_name">({{ item.real_name }})</text></text>
								<text class="item-text">招商数量: {{ item.zhaoshang_num || 0 }}</text>
								<text class="item-text">加入时间: {{ item.create_time }}</text>
							</view>
							<view class="status-text">正式水管家</view>
						</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { formatDate, request } from "@/utils/tool";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				currentTab: 0,
				list: [],
				tabList: [{
					name: '我邀请的',
					// count: 2
				}, {
					name: '间接邀请的'
				}]
			}
		},
		methods: {
			handleToDetail(rowItem) {
				uni.navigateTo({
					url: "/pages/index/my-team/detail?id=" + rowItem.id,
				})
			},
			async upCallback(ev) {
				const { num, size } = ev
				const resp = await request({
					url: "/team/lists",
					method: "GET",
					data: {
						page_no: num,
						page_size: size,
						type: this.currentTab + 1
					}
				})
				if (num === 1) this.list = []
				const { lists, count } = resp.data
				this.list.push(...lists.map(item => {
					const { create_time } = item
					item.create_time = create_time ? formatDate(create_time) : ''
					return item
				}))
				this.mescroll.endBySize(lists.length, count)
			},
			handleTabChange(index) {
				this.currentTab = index
				this.mescroll.triggerDownScroll()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.my-team {
		.record-list {
			padding: 24rpx 20rpx 0;
			box-sizing: border-box;
			position: relative;

			.record-item {
				padding: 16rpx 28rpx 16rpx 40rpx;
				display: flex;
				align-items: center;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-bottom: 16rpx;

				&:last-child {
					margin-bottom: 0;
				}

				.status-text {
					align-self: flex-start;
					margin: 6rpx 0 0 auto;
					font-weight: 400;
					font-size: 28rpx;
					color: #3780F5;
					line-height: 44rpx;
				}

				.item-info {
					margin-left: 16rpx;
					display: flex;
					flex-flow: column;

					.item-text {
						font-weight: 400;
						font-size: 24rpx;
						color: #646464;
						line-height: 44rpx;
					}
				}

				.item-avatar {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>